package com.sitech.portal.report.action;

import com.sitech.ibnms.core.JGridBaseAction;
import com.sitech.portal.report.form.SysModuleUseCountForm;
import com.sitech.portal.report.service.ITbSysModuleUseLogService;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2015/6/23.
 */
public class TbSysModuleUseLogAction extends JGridBaseAction{
    private ITbSysModuleUseLogService tbSysModuleUseLogService;

    private String path;
    private boolean flag=true;
    private Integer topN;
    private String startDate;
    private String endDate;
    private List<SysModuleUseCountForm> modulesTopN;

    public String add(){
        tbSysModuleUseLogService.addModuleUserLog(path, this.getCurrentUser().getLOGIN_ID());
        return SUCCESS;
    }

    public String useCount(){
        this.setResult(tbSysModuleUseLogService.countModuleUseCount(this.getPageForm()));
        return SUCCESS;
    }

    public String useCountTopNByTimeInterval() {
        Date start = null;
        Date end = null;
        try {
            if(startDate != null && startDate != "") {
                start = new SimpleDateFormat("yyyy-MM-dd").parse(startDate);
            }
            if(endDate != null && endDate != "") {
                end = new SimpleDateFormat("yyyy-MM-dd").parse(endDate);
            }
        } catch (ParseException e) {
            log.error(e.getCause());
        }
        modulesTopN = tbSysModuleUseLogService.countModuleUseCountByTimeInterval(start, end,  topN);

        return SUCCESS;
    }

    public void setTbSysModuleUseLogService(ITbSysModuleUseLogService tbSysModuleUseLogService) {
        this.tbSysModuleUseLogService = tbSysModuleUseLogService;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public String getPath() {
        return path;
    }

    public boolean isFlag() {
        return flag;
    }

    public void setEndDate(String endDate) {
        this.endDate = endDate;
    }

    public void setTopN(Integer topN) {
        this.topN = topN;
    }

    public void setStartDate(String startDate) {
        this.startDate = startDate;
    }

    public List<SysModuleUseCountForm> getModulesTopN() {
        return modulesTopN;
    }
}
